#region Usings

using System;
using System.Collections;
using System.Security.Principal;
using System.Web;
using Moq;
using NUnit.Framework;
using Karma.Framework.Core.Security;
using Karma.Framework.Core.Web;
using IPrincipal=Karma.Framework.Core.Security.IPrincipal;

#endregion

namespace Karma.Framework.Core.Test.Security
{
    [TestFixture]
    public class ContextFixture
    {
        #region Setup/Teardown

        [SetUp]
        public void TestSetUp()
        {
            var context = new Mock<HttpContextBase>(MockBehavior.Loose);
            var session = new Mock<HttpSessionStateBase>(MockBehavior.Loose);
            var items = new Hashtable();
            context.Expect(ctx => ctx.Session).Returns(session.Object);
            context.ExpectGet(ctx => ctx.Items).Returns(items);
            HttpContextFactory.SetHttpContext(context.Object);
            Context.Initialize(new User());
        }

        #endregion

        [Test]
        [Ignore]
        public void ContextFailureTest()
        {
            Assert.IsNull(Context.User);
        }

        [Test]
        [Ignore]
        public void ContextTest()
        {
            Assert.IsNotNull(Context.User);
            Assert.IsTrue(Context.User.IsInRole(String.Empty));
        }
    }

    public class User : IPrincipal
    {
        public bool Access { get; set; }

        #region Implementation of IUser

        public bool IsInRole(string serviceName)
        {
            return Access;
        }

        #endregion

        #region IPrincipal Members

        public IIdentity Identity
        {
            get { throw new InvalidOperationException(); }
            set { throw new InvalidOperationException(); }
        }

        public string Username
        {
            get { throw new InvalidOperationException(); }
            set { throw new InvalidOperationException(); }
        }

        #endregion
    }
}